{
	template:`
	<a-spin :spinning="!loadOver">
	<a-page-header>
		<template #title>
			流程： {{define.name}} ( {{define.identity}} v{{define.version}}) 
		</template>
		<template #subTitle>
			<span v-if="instance.doneStatus=='Y'">已完成</span>
		</template>
		<template #extra>
			<a-button v-if="loadOver&&!instance.oid" type="primary success" @click="startFlow();">启动</a-button>
			<a-button v-if="loadOver&&linkOptions.length>0" type="primary" @click="processFlow();">提交</a-button>
			<a-button v-if="loadOver&&instance.oid" @click="viewFlow();">流程图</a-button>
			<m-back v-if="isOpen" @click="back(false);">关闭</m-back>
		</template>
		<a-card :hoverable="true" :bodyStyle="{padding:'20px 20px 0'}">
			<a-form class="index-form" :wrapper-col="{span:24}">
				<a-row :gutter="10">
					<a-col v-if="business.oid" :span="24">
						<a-form-item :label="business.type" class="index-form-item">
							{{business.title}}
						</a-form-item>
					</a-col>
					<a-col v-if="instance.currentSection.oid" :span="24">
						<a-form-item label="当前环节" class="index-form-item">
							{{instance.currentSection.name}} ( {{instance.currentSection.identity}} )
						</a-form-item>
					</a-col>
					<a-col v-if="!instance.oid" :span="24">
						<a-form-item label="启动环节" class="index-form-item">
							{{define.startSection.name}}
						</a-form-item>
					</a-col>
					<template v-if="linkOptions.length>0">
					<a-col :span="24">
						<a-form-item label="下一步" class="index-form-item">
							<a-radio-group :options="linkOptions" v-model:value="selected.selectLink" @change="selectNextHandler()" />
						</a-form-item>
					</a-col>
					<a-col v-if="instance.currentSection.oid&&instance.currentSection.forwardable=='Y'&&(!selected.selectLink.oid)" :span="24">
						<a-form-item label="转发给" class="index-form-item">
							<a-button type="primary" @click="selectOneAdmin(selected,'adminList',getForwardOrgId(),getForwardRoleId())">选择</a-button>
							<a-tag style="margin:3px 0 3px 6px;" v-for="admin in selected.adminList" color="processing">{{admin.realname}}</a-tag>
						</a-form-item>
					</a-col>
					<a-col v-else :span="24">
						<a-form-item label="意见" class="index-form-item">
							<a-textarea v-model:value="selected.opinion" placeholder="请填写处理意见" auto-size/>
						</a-form-item>
					</a-col>
					</template>
					<template v-if="selected.selectLink.isNext=='Y'">
						<a-col v-if="selected.selectLink.toOption=='OU'" :span="24">
							<a-form-item label="单选执行人" class="index-form-item">
								<a-button v-if="selected.selectable" type="primary" @click="selectOneAdmin(selected,'adminList',getToOrgId(),getToRoleId())">选择</a-button>
								<a-tag style="margin:3px 0 3px 6px;" v-for="admin in selected.adminList" color="processing">{{admin.realname}}</a-tag>
							</a-form-item>
						</a-col>
						<a-col v-if="selected.selectLink.toOption=='MU'" :span="24">
							<a-form-item label="多选执行人" class="index-form-item">
								<a-button v-if="selected.selectable" type="primary" @click="selectManyAdmin(selected,'adminList',getToOrgId(),getToRoleId())">选择</a-button>
								<a-tag style="margin:3px 0 3px 6px;" v-for="admin in selected.adminList" color="processing">{{admin.realname}}</a-tag>
							</a-form-item>
						</a-col>
					</template>
					<a-col v-if="selected.selectLink.isNext=='B'" :span="24">
						<a-form-item label="退回给" class="index-form-item">
							<a-tag style="margin:3px 0 3px 6px;" color="processing">{{business.applyUser.realname}}</a-tag>
						</a-form-item>
					</a-col>
				</a-row>
			</a-form>
		</a-card>
	</a-page-header>
	<a-page-header v-if="instanceSectionList.length>0" title="流程执行情况" style="padding-top:0;">
		<a-card :hoverable="true" :bodyStyle="{padding:0}">
		    <a-table :data-source="instanceSectionList" size="small" :pagination="false">
		        <a-table-column key="flowIndex" title="" width="50" align="center" data-index="flowIndex"></a-table-column>
		        <a-table-column key="flowSection.name" title="环节" :data-index="['flowSection','name']"></a-table-column>
		        <a-table-column key="user.realname" title="执行人" :data-index="['user','realname']"></a-table-column>
		        <a-table-column key="toDesc" title="结果" data-index="toDesc"></a-table-column>
		        <a-table-column key="remark" title="执行时间">
                    <template #default="{ record,index }">
                        {{new Date(record.acceptDate).formatShow('yyyy-MM-dd HH:mm')}} - {{new Date(record.doneDate).formatShow('yyyy-MM-dd HH:mm')}}
                    </template>
                </a-table-column>
		        <a-table-column key="opinion" title="" data-index="opinion">
                    <template #default="{ text,record,index }">
                        <a-tooltip :title="text">
                        {{text&&text.length>16?(text.substring(0,16)+'...'):text}}
                        </a-tooltip>
                    </template>
		        </a-table-column>
		    </a-table>
		</a-card>
	</a-page-header>
	</a-spin>
	`,
	props: ['localeZh','param','parentVue'],
	data:function(){
		return {
			loadOver:false,
			isOpen:false,
			orgGroup:'',
			roleGroup:'',
			business:{},
			instance:{currentSection:{}},
			define:{startSection:{}},
			instanceSection:{},
			sectionLinks:[],
			instanceSectionList:[],
			linkOptions:[],
			selected:{
				instance:{},
				selectLink:{oid:''},
				opinion:'',
				adminList:[],
				selectable:false
			},
          	showModal:false,modalV3:null,
		};
	},
	mounted(){
	//this.param: {isOpen:false,business:{oid:'业务主键',busiService:'业务service类'}}
		this.isOpen=this.param.isOpen;
		this.business=this.param.business;
		this.initInfo();
	},
	methods:{
		initInfo:function(){
		    this.initDict('manage.model.AdminLogin');
			this.selected.adminList=[];
			this.selected.selectLink={oid:''};
			this.linkOptions=[];
			this.loadInfo();
		},
		loadInfo:function(){
			this.loadOver=false;
			this.requestData('action/flow/flow/getFlowInfo',{business:this.business},function(data){
				if(data.code==0){
					this.business=data.business;
					this.instance=data.instance;
					this.selected.instance=data.instance;
                    this.selected.selectable=this.business.nextSelectUser!='N';
                    this.orgGroup=this.business.toOrg;
                    this.roleGroup=this.business.toRole;
					this.define=data.define;
					this.instanceSection=data.instanceSection;
					this.sectionLinks=data.sectionLinks;
					this.instanceSectionList=data.instanceSectionList;
					if(this.sectionLinks){
						for(var i=0;i<this.sectionLinks.length;i++){
							var link=this.sectionLinks[i];
							var to=link.toSection.oid?('('+link.toSection.name+')'):'';
							if(link.isNext=='N') to='(结束)';
							this.linkOptions.push({label:link.toDesc+to,value:link});
						}
						if(this.linkOptions.length>0){
							if(this.instance.currentSection.forwardable=='Y'){
								this.linkOptions.push({label:"转发",value:{forwardable:'Y'}});
							}
							this.selected.selectLink=this.linkOptions[0].value;
						}
					}
					this.selectNextHandler();
				}else{
					this.$message.error(data.msg);
					if(this.isOpen) this.back(false);
				}
				this.loadOver=true;
			}.bind(this));
		},
		selectNextHandler:function(){
		    this.selected.adminList=[];
            let user=this.business.nextDefaultUser;
		    if(this.selected.selectLink.isNext=='Y'&&user&&user.length>0){
		        if(this.selected.selectLink.toOption=='OU'){
                    this.selected.adminList.push({oid:user[0],realname:this.dict('manage.model.AdminLogin',user[0])});
		        }else if(this.selected.selectLink.toOption=='MU'){
                    for(let i=0;i<this.business.nextDefaultUser.length;i++){
                        let u=this.business.nextDefaultUser[i];
                        this.selected.adminList.push({oid:u,realname:this.dict('manage.model.AdminLogin',u)});
                    }
		        }
		    }
		},
		getToOrgId:function(){
		    let too=this.business.toOrgOption||this.selected.selectLink.toOrgOption;
		    if(this.orgGroup&&this.orgGroup.length){
		        return this.orgGroup;
		    }else if("Y"==too){
		        return this.selected.selectLink.toOrg;
		    }else if("A"==too){
                return this.business.applyOrg.oid;
            }else if("B"==too){
                return this.business.applyOrg.parent.oid;
            }
            return "";
		},
		getToRoleId:function(){
		    if(this.roleGroup&&this.roleGroup.length){
		        return this.roleGroup;
		    }else{
		        return this.selected.selectLink.toRole;
		    }
		},
		getForwardOrgId:function(){
		    let too=this.business.toOrgOption||this.instanceSection.toOrgOption;
		    if(this.orgGroup&&this.orgGroup.length){
		        return this.orgGroup;
		    }else if("Y"==too){
		        return this.instanceSection.toOrg;
		    }else if("A"==too){
                return this.business.applyOrg.oid;
            }else if("B"==too){
                return this.business.applyOrg.parent.oid;
            }
            return "";
		},
		getForwardRoleId:function(){
		    if(this.roleGroup&&this.roleGroup.length){
		        return this.roleGroup;
		    }else{
		        return this.instanceSection.toRole;
		    }
		},
		startFlow:function(){
			this.$confirm({
				title: '启动流程',
				content: '确定要启动流程吗?',
				onOk: function(){
					this.requestData('action/flow/flow/doStart',
						{business:this.business,adminList:this.adminList},
						function(data){
							if(data.code==0){
								this.setBack(true,this.selected);
								this.initInfo();
								this.$message.success(data.msg);
							}else{
								this.$message.error(data.msg);
							}
						}.bind(this)
					);
				}.bind(this)
			});
		},
		processFlow:function(){
			this.$confirm({
				title: '提交流程',
				content: '确定要提交流程吗?',
				onOk: function(){
					this.requestData('action/flow/flow/doProcess',
						this.selected,
						function(data){
							if(data.code==0){
								this.back(true,this.selected);
								this.initInfo();
								this.$message.success(data.msg);
							}else{
								this.$message.error(data.msg);
							}
						}.bind(this)
					);
				}.bind(this)
			});
		},
		viewFlow:function(){
          	this.openPage('page/base/flow/viewFlowDefine.js',
      			{defineOid:this.define.oid,instanceOid:this.instance.oid},
      			function(flag,obj){}.bind(this),
		        '800px'
	        );
		},
	}
}